package com.agenda.comum;

import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.net.Socket;

public abstract class ObjectEnvioInformacao implements EnvioInformacao {

	protected OutputStream output;
	protected Socket sck;

	public abstract Serializable getObjeto();

	public void enviar(OutputStream output) throws Exception {
		this.output = output;

		ObjectOutputStream objectOutput = new ObjectOutputStream(this.output);

		Serializable[] objetos = getObjetos();
		if (objetos == null)
			objectOutput.writeObject(getObjeto());
		else {
			for (Serializable serializable : objetos)
				objectOutput.writeObject(serializable);
		}
	}

	protected Serializable[] getObjetos() {
		return null;
	}

	@Override
	public void setSocket(Socket socket) {
		this.sck = socket;
	}

	public Socket getSck() {
		return sck;
	}
}
